In rgrep, check matching files before excluding files
authorSpencer Baugh <sbaugh@janestreet.com>
Sun, 26 May 2024 13:26:09 +0000 (09:26 -0400)
committerStefan Kangas <stefankangas@gmail.com>
Sun, 2 Jun 2024 10:43:09 +0000 (12:43 +0200)
commitb71fa27987d89774c84b0c9362ddfb4a0f679856
tree454869738f3c9774af5c6044e17db4d58607a4a0
parent7983f882823bafd5dd834c24d4defb26525f687b
In rgrep, check matching files before excluding files

There are a lot of excluding globs, and checking them all is expensive.
The files glob (i.e. the glob for files we actually want) is usually
just one or two entries, so it's quite fast to check.

If find checks the files glob first and then the excluding glob, it has
to do much less checking (since the files glob will substantially narrow
down the set of files on its own), and find performance is much better.

In my benchmarking, this takes (rgrep "foo" "*.el" "~/src/emacs/trunk/")
from ~410ms to ~130ms.

Further optimizations are possible now that the ignores and matched
files are in the same <F> argument which can be rearranged more easily
without compatibility issues; I'll do those optimizations in later
commits.

* lisp/progmodes/grep.el (rgrep-find-ignores-in-<f>): Add.
* lisp/progmodes/grep.el (rgrep-default-command): Check
rgrep-find-ignores-in-<f> and move the excluded files glob to part of
the "files" argument.  (Bug#71179)
lisp/progmodes/grep.el